package kotan.controller._kotan;

import java.io.ByteArrayInputStream;
import java.io.ObjectInputStream;

import javax.servlet.http.HttpServletResponse;

import kotan.datastore.api.DatastoreApiUtil;
import kotan.datastore.api.Key;

import org.slim3.controller.Controller;
import org.slim3.controller.Navigation;
import org.slim3.controller.upload.FileItem;
import org.slim3.datastore.Datastore;


public class DeleteController extends Controller {

    @Override
    public Navigation run() throws Exception {
        FileItem keyItem = requestScope("key");
        ObjectInputStream input =
            new ObjectInputStream(new ByteArrayInputStream(keyItem.getData()));
        Key key = (Key) input.readObject();
        Datastore.delete(DatastoreApiUtil.convert(key));
        response.setStatus(HttpServletResponse.SC_OK);
        return null;
    }
}
